package mmc.networking;

import mmc.server.Player;
import mmc.server.RemoteClient;

@SuppressWarnings("serial")
public class ObjectMoving extends Message{

	int id;
	float x, y, z, vx, vy, vz, pitch, yaw;
	
	public ObjectMoving(int id, float x, float y, float z, float vx, float vy, float vz, float pitch, float yaw){
		this.id = id;
		this.x=x;
		this.y=y;
		this.z=z;
		this.vx=vx;
		this.vy=vy;
		this.vz=vz;
		this.pitch = pitch;
		this.yaw = yaw;
	}
	
	public ObjectMoving(int id, float x, float y, float z, float vx, float vy, float vz){
		this(id,x,y,z,vx,vy,vz,Float.NaN,Float.NaN);
	}
	
	@Override
	public void executeOnServer(RemoteClient context) {
		if(id==-1){ //the player himself
			Player o = context.getPlayer();
			
			if(x == o.x && y == o.y && z == o.z && vy == o.vy && vx == o.vx && vz == o.vz && o.yaw == yaw && o.pitch == pitch){

			}else{
				o.x = x;
				o.y = y;
				o.z = z;
				o.vx = vx;
				o.vy = vy;
				o.vz = vz;
				o.pitch = pitch;
				o.yaw = yaw;
				o.dirty = true;
			}
		}else
			throw new RuntimeException("Implemented for player only yet");
	}
}
